<template>
  <div class="es-dropdown">
    <div class="es-dropdown-button">
      <div class="es-button-group">
        <button class="es-button es-round group-item">
          <span class="es-dropdown-selected-header">{{ filterOps.name }}</span>
        </button>
        <button class="es-button es-round group-item" @click="showFilter">
          <span class="es-iconfont icon-arrow-down"></span>
        </button>
      </div>
    </div>
    <div
      class="es-dropdown-menu"
      :class="isFilter ? 'show position-absolute' : ''"
    >
      <div class="es-dropdown-inner">
        <ul class="es-dropdown-contents">
          <!-- <li class="dropdown-item">
                        <div class="dropdown-header">选项</div>
                      </li> -->
          <li
            class="dropdown-item"
            v-for="(item, index) in data"
            :key="index"
            :class="item.value === filterOps.value ? 'active' : ''"
          >
            <div class="dropdown-item">
              <a href="javascript:;" @click="filterHandle(item)">
                {{ item.name }}
              </a>
            </div>
          </li>
          <!-- <li class="dropdown-divider"></li>
                       -->
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "DropDown",
  props: {
    data: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      isFilter: false,
      filterOps: {
        name: "Option0",
        value: 0,
      },
    };
  },
  methods: {
    showFilter() {
      this.isFilter = this.isFilter ? false : true;
    },
    filterHandle(v) {
      this.filterOps = v;
      this.isFilter = false;
    },
  },
};
</script>

<style lang="scss"></style>
